﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class WebPart : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!this.IsPostBack)
            {
                RadioButtonList1.Items.Clear();
                foreach (WebPartDisplayMode mode in myWebPartManager.DisplayModes)
                {
                    if (mode.IsEnabled(myWebPartManager))
                    {
                        RadioButtonList1.Items.Add(mode.Name);
                    }
                }
            }
            RadioButtonList1.SelectedValue = myWebPartManager.DisplayMode.Name;
        }
    }
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        WebPartDisplayMode mode = myWebPartManager.SupportedDisplayModes[RadioButtonList1.SelectedValue];
        if (mode != null)
            myWebPartManager.DisplayMode = mode;
    }
}